import math
import os
import re
import struct
import threading
from collections import defaultdict
from time import sleep

import pandas as pd
import numpy as np
import time

from base_config import BASE_PATH
from commen.log import Logger
import openpyxl
import datetime
import commen.config
from tools.read_json import read_json


def percentage_error(data_error, total, sheet_obj):
    dict_percentage = {}
    for i in range(8, 100):
        key = sheet_obj.cell(1, i).value
        if key == "差异项":
            break
        if data_error.get(key):
            dict_percentage[key] = f"{key}的正确率：{(data_error.get(key) / total) * 100}%"
            print(f"{key}的正确率：{100 - round((data_error.get(key) / total) * 100, 2)}%")
        else:
            dict_percentage[key] = f"{key}的正确率：100%"
            print(f"{key}的正确率：100%")
    # print(dict_percentage)


def ImuDatacontinuity():
    # ---------读取config文件获取筛选字段内容--------------------------
    mpukey = commen.config.global_config.getRaw('keywords', 'suanfagnss')
    caninskey = commen.config.global_config.getRaw('keywords', 'cankeygnss')

    # ---------读取config文件获取筛选字段内容--------------------------
    logger = Logger(logger='TestMylog').getlog()
    # -----------------------创建excel--------------------------------------------
    # 获取当前时间
    time_now = time.strftime("%Y%m%d-%H%M", time.localtime())
    # 获取当前路径
    result_root = os.getcwd()
    root = os.getcwd()
    result_path = result_root + r'\result' + "\\" + time_now
    log_path = root + r'\original-logfile' + '\\'
    # -----遍历对比log路径获取要对比的文件名路径信息----------------------
    for root, dirs, files in os.walk(log_path):
        for file in files:
            if "Data" in file:
                aa = os.path.join(root, file)
            if "can" in file:
                bb = os.path.join(root, file)

    # -----遍历对比log路径获取要对比的文件名路径信息----------------------
    book = openpyxl.Workbook()  # 打开一个将写的文件
    sheet = book.create_sheet(index=0)  # 在将写的文件创建sheet
    saveExcel = result_path + "GNSS数据准确性验证.xlsx"
    sheet.cell(1, 2).value = "mpu上GNSS数据的系统时间"
    sheet.cell(1, 3).value = "can上GNSS数据系统时间"
    sheet.cell(1, 4).value = "mpu上GNSS数据内容"
    sheet.cell(1, 5).value = "can上GNSS数据内容"
    sheet.cell(1, 6).value = "对比数据信息"
    sheet.cell(1, 7).value = "数据是否一致"
    sheet.cell(1, 8).value = "解算卫星数"
    sheet.cell(1, 9).value = "周内秒-周"
    sheet.cell(1, 10).value = "周内秒-秒"
    sheet.cell(1, 11).value = "RTK经度"
    sheet.cell(1, 12).value = 'RTK纬度'
    sheet.cell(1, 13).value = 'RTK高程'
    sheet.cell(1, 14).value = '东向速度'
    sheet.cell(1, 15).value = '北向速度'
    sheet.cell(1, 16).value = '地向速度'
    sheet.cell(1, 17).value = '航向角'
    sheet.cell(1, 18).value = 'RTK经度精度'
    sheet.cell(1, 19).value = 'RTK纬度精度'
    sheet.cell(1, 20).value = 'RTK高程精度'
    sheet.cell(1, 21).value = '水平分量精度因子'
    sheet.cell(1, 22).value = '位置精度因子'
    sheet.cell(1, 23).value = '垂直分量精度因子'
    sheet.cell(1, 24).value = '域控时间'
    sheet.cell(1, 25).value = '差异项'

    row = 1
    # -----------------------创建excel--------------------------------------------

    canfile = open(bb, 'r', encoding='gbk')  # 打开can.log目标文件
    dataprocfile = open(aa, 'r', encoding='UTF-8')  # 打开dataproc.log文件
    logger.info("打开目标文件")
    canlines = canfile.readlines()
    mpulines = dataprocfile.readlines()
    logger.info("获取内容")

    mpusystemtimelist = []  # mpu数据的系统时间
    cansystemtimelist = []  # can数据的系统时间
    mpumessagelist = []  # mpu数据内容
    canmessagelist = []  # can数据内容
    mpu_utctimelist = []  # mpuutc时间
    can_utctimelist = []  # canutc时间
    logger.info("开始逐行读取")

    for lines in mpulines:  # 对内容 进行逐行读取

        if mpukey in lines:  # 通过关键字获取数据信息并存入到list中

            mpusystemtime = lines[:lines.index("<thread")]
            mpusystemtimelist.append(mpusystemtime.rstrip())
            mpumessage = lines.split("+0:")
            mpumessage1 = mpumessage[1].lstrip().replace(" ", "").replace("-", "").replace("+10:", "").replace("+20:",
                                                                                                               "").replace(
                "+30:", "").replace("+40:", "").replace("+50:", "").replace("+60:", "").replace("+70:", "").replace(
                "+80:", "").replace(")", "")
            mpumessagelist.append(mpumessage1.rstrip())
            mpu_utctimelist.append(mpumessage1.rstrip()[5:16])

            # utc时间：str(mpumessage1.rstrip()[5:7])+" "+str(mpumessage1.rstrip()[7:9])+" "+str(mpumessage1.rstrip()[9:11])+" "+str(mpumessage1.rstrip()[11:13])+" "+str(mpumessage1.rstrip()[13:15])
    for canline in canlines:  # 对内容 进行逐行读取
        if caninskey in canline:  # 通过关键字获取数据信息并存入到list中
            systemtime = canline[:canline.index("Rx")]
            cansystemtimelist.append(systemtime.rstrip())
            canmessage = canline.split("s-fd-brs 64")
            canmessagelist.append(canmessage[1].replace(" ", ""))
            can_utctimelist.append(canmessage[1].replace(" ", "")[4:15])
    pic_dict = defaultdict(int)
    total = 0
    signal_config = read_json(BASE_PATH + os.sep + "confige" + os.sep + "can_gnss_matrix.json", abs_path=True)

    def boundary_check(main_key, value):
        if value >= signal_config[main_key]["max"]:
            value = signal_config[main_key]["max"]
        if value <= signal_config[main_key]["min"]:
            value = signal_config[main_key]["min"]
        return value

    for i in mpu_utctimelist:
        wash_data = {}
        if i in can_utctimelist:
            total += 1
            logger.info("开始进行对比")
            row = row + 1
            mpu_number = mpu_utctimelist.index(str(i))
            can_number = can_utctimelist.index(str(i))
            # -----------------------------------------------解算卫星数（4.18 check）---------------------------------------------
            mpu_GNSSinf1PVTnumSV1 = mpumessagelist[mpu_number][18:20]
            mpu_GNSSinf1PVTnumSV2 = int(mpu_GNSSinf1PVTnumSV1, 16)
            mpu_GNSSinf1PVTnumSV2 = boundary_check("解算卫星数", mpu_GNSSinf1PVTnumSV2)
            mpu_GNSSinf1PVTnumSV3 = mpu_GNSSinf1PVTnumSV2 << 2
            mpu_GNSSinf1PVTnumSV_Decimal = mpu_GNSSinf1PVTnumSV3
            mpu_GNSSinf1PVTnumSV_Hexadecimal = str(hex(int(mpu_GNSSinf1PVTnumSV_Decimal))).replace("0x", "")
            can_GNSSinf1PVTnumSV_Hexadecimal = canmessagelist[can_number][50:52]
            can_GNSSinf1PVTnumSV_Decimal = int(str(canmessagelist[can_number][50:52]), 16)
            wash_data[f"{mpu_GNSSinf1PVTnumSV_Decimal=}"] = f"{can_GNSSinf1PVTnumSV_Decimal=}"
            # -----------------------------------------------周内秒-周（4.18 check）---------------------------------------------
            mpu_GNSSinf1PVTweek = mpumessagelist[mpu_number][20:24]
            mpu_GNSSinf1PVTweek1 = int(mpu_GNSSinf1PVTweek, 16)
            mpu_GNSSinf1PVTweek1 = boundary_check("周内秒-周", mpu_GNSSinf1PVTweek1)
            mpu_GNSSinf1PVTweek2 = mpu_GNSSinf1PVTweek1 << 4
            mpu_GNSSinf1PVTweek_Decimal = mpu_GNSSinf1PVTweek2
            mpu_GNSSinf1PVTweek_Hexadecimal = str(hex(int(mpu_GNSSinf1PVTweek_Decimal))).replace("0x", "")
            can_GNSSinf1PVTweek_Hexadecimal = canmessagelist[can_number][90:94]
            can_GNSSinf1PVTweek_Decimal = int(str(canmessagelist[can_number][90:94]), 16)
            wash_data[f"{mpu_GNSSinf1PVTweek_Decimal=}"] = f"{can_GNSSinf1PVTweek_Decimal=}"
            # -----------------------------------------------周内秒-秒（4.18 check）---------------------------------------------
            mpu_GNSSinf1PVTiTOW = mpumessagelist[mpu_number][24:32]
            mpu_GNSSinf1PVTiTOW1 = int(mpu_GNSSinf1PVTiTOW, 16)
            mpu_GNSSinf1PVTiTOW1 = boundary_check("周内秒-秒", mpu_GNSSinf1PVTiTOW1)
            mpu_GNSSinf1PVTiTOW_Decimal = mpu_GNSSinf1PVTiTOW1
            mpu_GNSSinf1PVTiTOW_Hexadecimal = str(hex(int(mpu_GNSSinf1PVTiTOW1))).replace("0x", "")
            can_GNSSinf1PVTiTOW_Hexadecimal = canmessagelist[can_number][94:102]
            can_GNSSinf1PVTiTOW_Decimal = int(str(canmessagelist[can_number][94:102]), 16)
            wash_data[f"{mpu_GNSSinf1PVTiTOW_Decimal=}"] = f"{can_GNSSinf1PVTiTOW_Decimal=}"
            # -----------------------------------------------RTK经度（4.18 check）---------------------------------------------
            mpu_RTK_Longitude_numbei = mpumessagelist[mpu_number][32:48]
            mpu_RTK_Longitude_numbei1 = int(mpu_RTK_Longitude_numbei, 16)
            mpu_RTK_Longitude_numbei2 = mpu_RTK_Longitude_numbei1 / (10**10)
            mpu_RTK_Longitude_numbei2 = boundary_check("RTK经度", mpu_RTK_Longitude_numbei2)
            mpu_RTK_Longitude_numbei2 = int(mpu_RTK_Longitude_numbei2/0.0000000013097)
            mpu_RTK_Longitude_Decimal = mpu_RTK_Longitude_numbei2 << 2
            mpu_RTK_Longitude_Hexadecimal = hex(mpu_RTK_Longitude_Decimal)[2:].upper()
            can_RTK_Longitude_Hexadecimal = canmessagelist[can_number][40:50]
            can_RTK_Longitude_Decimal = int(str(can_RTK_Longitude_Hexadecimal), 16)
            wash_data[f"{mpu_RTK_Longitude_Decimal=}"] = f"{can_RTK_Longitude_Decimal=}"
            # -----------------------------------------------RTK纬度（4.18 check）---------------------------------------------
            mpu_RTK_Latitude_numbei = mpumessagelist[mpu_number][48:64]
            mpu_RTK_Latitude_numbei1 = int(mpu_RTK_Latitude_numbei, 16)
            mpu_RTK_Latitude_numbei2 = mpu_RTK_Latitude_numbei1 / (10**10)
            mpu_RTK_Latitude_numbei2 = boundary_check("RTK纬度", mpu_RTK_Latitude_numbei2)
            mpu_RTK_Latitude_numbei2 = int(mpu_RTK_Latitude_numbei2/0.0000000013097)
            mpu_RTK_Latitude_Decimal = mpu_RTK_Latitude_numbei2 << 3
            mpu_RTK_Latitude_Hexadecimal = hex(mpu_RTK_Latitude_Decimal)[2:].upper()
            can_RTK_Latitude_Hexadecimal = canmessagelist[can_number][30:40]
            can_RTK_Latitude_Decimal = int(str(can_RTK_Latitude_Hexadecimal), 16)
            wash_data[f"{mpu_RTK_Latitude_Decimal=}"] = f"{can_RTK_Latitude_Decimal=}"
            # -----------------------------------------------RTK高程（4.18 check）---------------------------------------------
            mpu_RTK_Height_numbei = mpumessagelist[mpu_number][64:80]
            mpu_RTK_Height_numbei1 = int(mpu_RTK_Height_numbei, 16) / (10**6)
            mpu_RTK_Height_numbei1 = boundary_check("RTK高程", mpu_RTK_Height_numbei1)
            mpu_RTK_Height_numbei2 = mpu_RTK_Height_numbei1 + 1000
            mpu_RTK_Height_numbei3 = int(mpu_RTK_Height_numbei2 / 0.0023842)
            mpu_RTK_Height_Decimal = mpu_RTK_Height_numbei3 << 2
            mpu_RTK_Height_Hexadecimal = hex(mpu_RTK_Height_Decimal)[2:].upper()
            can_RTK_Height_Hexadecimal = canmessagelist[can_number][24:30]
            can_RTK_Height_Decimal = int(str(can_RTK_Height_Hexadecimal), 16)
            wash_data[f"{mpu_RTK_Height_Decimal=}"] = f"{can_RTK_Height_Decimal=}"
            # -----------------------------------------------东向速度（4.18 check）---------------------------------------------
            mpu_East_vehicle_speed = mpumessagelist[mpu_number][80:88]
            mpu_East_vehicle_speed1 = struct.unpack("I",
                                                    (int(str(mpu_East_vehicle_speed), 16)).to_bytes(4, byteorder='big'))
            mpu_East_vehicle_speed2 = struct.unpack("i", (mpu_East_vehicle_speed1[0]).to_bytes(4, byteorder='big'))
            mpu_East_vehicle_speed3 = mpu_East_vehicle_speed2[0] / (10**6)
            mpu_East_vehicle_speed3 = boundary_check("东向速度", mpu_East_vehicle_speed3)
            mpu_East_vehicle_speed3 = int(mpu_East_vehicle_speed3/0.0015259)
            # 0.0015259
            mpu_East_vehicle_Decimal1 = int(str(mpu_East_vehicle_speed3 << 7))
            if "-" in str(mpu_East_vehicle_Decimal1):
                mpu_East_vehicle_Decimal2 = int(str(mpu_East_vehicle_Decimal1).replace("-", ""))
                mpu_East_vehicle_Decimal = int(str(bin(~mpu_East_vehicle_Decimal2 + 1 & 0xFFfffe)), 2)
                mpu_East_vehicle_Hexadecimal = hex(int(str(mpu_East_vehicle_Decimal)))[2:].upper()
            else:
                mpu_East_vehicle_Decimal = mpu_East_vehicle_Decimal1
                mpu_East_vehicle_Hexadecimal = hex(int(str(mpu_East_vehicle_Decimal)))[2:].upper()
            can_East_vehicle_Hexadecimal = canmessagelist[can_number][78:84]
            can_East_vehicle_Decimal = int(str(can_East_vehicle_Hexadecimal), 16)
            wash_data[f"{mpu_East_vehicle_Decimal=}"] = f"{can_East_vehicle_Decimal=}"
            # -----------------------------------------------北向速度（4.18 check）---------------------------------------------
            mpu_North_vehicle_speed = mpumessagelist[mpu_number][88:96]
            mpu_North_vehicle_speed1 = struct.unpack("I", (int(str(mpu_North_vehicle_speed), 16)).to_bytes(4,
                                                                                                           byteorder='big'))
            mpu_North_vehicle_speed2 = struct.unpack("i", (mpu_North_vehicle_speed1[0]).to_bytes(4, byteorder='big'))
            mpu_North_vehicle_speed3 = mpu_North_vehicle_speed2[0] / (10**6)
            mpu_North_vehicle_speed3 = boundary_check("北向速度", mpu_North_vehicle_speed3)
            mpu_North_vehicle_speed3 = int(mpu_North_vehicle_speed3/0.0015259)
            mpu_North_vehicle_Decimal1 = int(str(mpu_North_vehicle_speed3 << 7))
            if "-" in str(mpu_North_vehicle_Decimal1):
                mpu_East_vehicle_Decimal2 = int(str(mpu_North_vehicle_Decimal1).replace("-", ""))
                mpu_North_vehicle_Decimal = int(str(bin(~mpu_East_vehicle_Decimal2 + 1 & 0xFFfffe)), 2)
                mpu_North_vehicle_Hexadecimal = hex(int(str(mpu_East_vehicle_Decimal)))[2:].upper()
            else:
                mpu_North_vehicle_Decimal = mpu_North_vehicle_Decimal1
                mpu_North_vehicle_Hexadecimal = hex(int(str(mpu_North_vehicle_Decimal)))[2:].upper()
            can_North_vehicle_speed_Hexadecimal = canmessagelist[can_number][84:90]
            can_North_vehicle_speed_Decimal = int(str(can_North_vehicle_speed_Hexadecimal), 16)
            wash_data[f"{mpu_North_vehicle_Decimal=}"] = f"{can_North_vehicle_speed_Decimal=}"
            # -----------------------------------------------地向速度（4.18 check）---------------------------------------------
            mpu_Downward_vehicle_speed = mpumessagelist[mpu_number][96:104]
            mpu_Downward_vehicle_speed1 = struct.unpack("I", (int(str(mpu_Downward_vehicle_speed), 16)).to_bytes(4,
                                                                                                                 byteorder='big'))
            mpu_Downward_vehicle_speed2 = struct.unpack("i",
                                                        (mpu_Downward_vehicle_speed1[0]).to_bytes(4, byteorder='big'))
            mpu_Downward_vehicle_speed3 = mpu_Downward_vehicle_speed2[0] / (10**6)
            mpu_Downward_vehicle_speed3 = boundary_check("地向速度", mpu_Downward_vehicle_speed3)
            mpu_Downward_vehicle_speed3 = int(mpu_Downward_vehicle_speed3/0.0018311)
            mpu_Downward_vehicle_Decimal1 = int(str(mpu_Downward_vehicle_speed3 << 1))
            if "-" in str(mpu_Downward_vehicle_Decimal1):
                mpu_Downward_vehicle_Decimal2 = int(str(mpu_Downward_vehicle_Decimal1).replace("-", ""))
                mpu_Downward_vehicle_Decimal = int(str(bin(~mpu_Downward_vehicle_Decimal2 + 1 & 0xfff8)), 2)
                mpu_Downward_vehicle_speed_Hexadecimal = hex(int(str(mpu_Downward_vehicle_Decimal)))[2:].upper()
            else:
                mpu_Downward_vehicle_Decimal = mpu_Downward_vehicle_Decimal1
                mpu_Downward_vehicle_speed_Hexadecimal = hex(int(str(mpu_Downward_vehicle_Decimal)))[2:].upper()
            can_Downward_vehicle_speed_Hexadecimal = canmessagelist[can_number][74:78]
            can_Downward_vehicle_speed_Decimal = int(str(can_Downward_vehicle_speed_Hexadecimal), 16)
            wash_data[f"{mpu_Downward_vehicle_Decimal=}"] = f"{can_Downward_vehicle_speed_Decimal=}"
            # -----------------------------------------------航向角（4.18 check）---------------------------------------------
            mpu_Track_angle = mpumessagelist[mpu_number][104:112]
            mpu_Track_angle1 = int(str(mpu_Track_angle), 16)/(10**6)
            mpu_Track_angle2 = boundary_check("航向角", mpu_Track_angle1)
            mpu_Track_angle2 = int(mpu_Track_angle2 / 0.010986)
            # mpu_Track_angle2 = boundary_check("航向角", mpu_Track_angle2)
            mpu_Track_angle_Decimal = mpu_Track_angle2 << 1
            mpu_Track_angle_Hexadecimal = hex(mpu_Track_angle_Decimal)[2:].upper()
            can_Track_angle_Hexadecimal = canmessagelist[can_number][16:20]
            can_Track_angle_Decimal = int(str(can_Track_angle_Hexadecimal), 16)
            wash_data[f"{mpu_Track_angle_Decimal=}"] = f"{can_Track_angle_Decimal=}"
            # -----------------------------------------------RTK经度精度（4.18 check）---------------------------------------------
            mpu_Longitude_STD = mpumessagelist[mpu_number][112:120]
            mpu_Longitude_STD1 = int(str(mpu_Longitude_STD), 16)
            mpu_Longitude_STD2 = mpu_Longitude_STD1 / (10**6)
            mpu_Longitude_STD2 = boundary_check("RTK经度精度", mpu_Longitude_STD2)
            mpu_Longitude_STD2 = int(mpu_Longitude_STD2/0.0015259)
            mpu_Longitude_STD_Decimal = mpu_Longitude_STD2
            mpu_Longitude_STD_Hexadecimal = hex(mpu_Longitude_STD_Decimal)[2:].upper()
            can_Longitude_STD_Hexadecimal = canmessagelist[can_number][66:70]
            can_Longitude_STD_Decimal = int(str(can_Longitude_STD_Hexadecimal), 16)
            wash_data[f"{mpu_Longitude_STD_Decimal=}"] = f"{can_Longitude_STD_Decimal=}"
            # -----------------------------------------------RTK纬度精度（4.18 check）---------------------------------------------
            mpu_Latitude_STD = mpumessagelist[mpu_number][120:128]
            mpu_Latitude_STD1 = int(str(mpu_Latitude_STD), 16)
            mpu_Latitude_STD2 = mpu_Latitude_STD1 / (10**6)
            mpu_Latitude_STD2 = boundary_check("RTK纬度精度", mpu_Latitude_STD2)
            mpu_Latitude_STD2 = int(mpu_Latitude_STD2/0.0015259)
            mpu_Latitude_STD_Decimal = mpu_Latitude_STD2
            mpu_Latitude_STD_Hexadecimal = hex(mpu_Latitude_STD_Decimal)[2:].upper()
            can_Latitude_STD_Hexadecimal = canmessagelist[can_number][62:66]
            can_Latitude_STD_Decimal = int(str(can_Latitude_STD_Hexadecimal), 16)
            wash_data[f"{mpu_Latitude_STD_Decimal=}"] = f"{can_Latitude_STD_Decimal=}"
            # -----------------------------------------------RTK高程精度（4.18 check）---------------------------------------------
            mpu_Height_STD = mpumessagelist[mpu_number][128:136]
            mpu_Height_STD1 = int(str(mpu_Height_STD), 16)
            mpu_Height_STD2 = mpu_Height_STD1 / (10**6)
            mpu_Height_STD2 = boundary_check("RTK高程精度", mpu_Height_STD2)
            mpu_Height_STD2 = int(mpu_Height_STD2/0.0015259)
            mpu_Height_STD_Decimal = mpu_Height_STD2
            mpu_Height_STD_Hexadecimal = hex(mpu_Height_STD_Decimal)[2:].upper()
            can_Height_STD_Hexadecimal = canmessagelist[can_number][58:62]
            can_Height_STD_Decimal = int(str(can_Height_STD_Hexadecimal), 16)
            wash_data[f"{mpu_Height_STD_Decimal=}"] = f"{can_Height_STD_Decimal=}"
            # -----------------------------------------------水平分量精度因子（4.18 check）---------------------------------------------
            mpu_Horizon_DOP = mpumessagelist[mpu_number][136:144]
            mpu_Horizon_DOP1 = int(str(mpu_Horizon_DOP), 16)
            mpu_Horizon_DOP2 = mpu_Horizon_DOP1 / (10**6)
            mpu_Horizon_DOP2 = boundary_check("水平分量精度因子", mpu_Horizon_DOP2)
            mpu_Horizon_DOP2 = int(mpu_Horizon_DOP2/0.092773)
            mpu_Horizon_DOP_Decimal = mpu_Horizon_DOP2 << 5
            mpu_Horizon_DOP_Hexadecimal = hex(mpu_Horizon_DOP_Decimal)[2:].upper()
            can_Horizon_DOP_Hexadecimal = canmessagelist[can_number][20:24]
            can_Horizon_DOP_Decimal = int(str(can_Horizon_DOP_Hexadecimal), 16)
            wash_data[f"{mpu_Horizon_DOP_Decimal=}"] = f"{can_Horizon_DOP_Decimal=}"
            # -----------------------------------------------位置精度因子（4.18 check）---------------------------------------------
            mpu_Position_DOP = mpumessagelist[mpu_number][144:152]
            mpu_Position_DOP1 = int(str(mpu_Position_DOP), 16)
            mpu_Position_DOP2 = mpu_Position_DOP1 / (10**6)
            mpu_Position_DOP2 = boundary_check("位置精度因子", mpu_Position_DOP2)
            mpu_Position_DOP2 = int(mpu_Position_DOP2/0.092773)
            mpu_Position_DOP_Decimal = mpu_Position_DOP2 << 5
            mpu_Position_DOP_Hexadecimal = hex(mpu_Position_DOP_Decimal)[2:].upper()
            can_Position_DOP_Hexadecimal = canmessagelist[can_number][52:56]
            can_Position_DOP_Decimal = int(str(can_Position_DOP_Hexadecimal), 16)
            wash_data[f"{mpu_Position_DOP_Decimal=}"] = f"{can_Position_DOP_Decimal=}"
            # -----------------------------------------------垂直分量精度因子（4.18 check）---------------------------------------------
            mpu_Vertical_DOP = mpumessagelist[mpu_number][152:160]
            mpu_Vertical_DOP1 = int(str(mpu_Vertical_DOP), 16)
            mpu_Vertical_DOP2 = mpu_Vertical_DOP1 / (10**6)
            mpu_Vertical_DOP2 = boundary_check("垂直分量精度因子", mpu_Vertical_DOP2)
            mpu_Vertical_DOP2 = int(mpu_Vertical_DOP2/0.092773)
            mpu_Vertical_DOP_Decimal = mpu_Vertical_DOP2 << 5
            mpu_Vertical_DOP_Hexadecimal = hex(mpu_Vertical_DOP_Decimal)[2:].upper()
            can_Vertical_DOP_Hexadecimal = canmessagelist[can_number][70:74]
            can_Vertical_DOP_Decimal = int(str(can_Vertical_DOP_Hexadecimal), 16)
            wash_data[f"{mpu_Vertical_DOP_Decimal=}"] = f"{can_Vertical_DOP_Decimal=}"
            # -----------------------------------------------域控时间（4.18 check）---------------------------------------------
            mpu_Timestamp_to_can = mpumessagelist[mpu_number][160:172]
            # mpu_Timestamp_to_can = boundary_check("域控时间", mpu_Timestamp_to_can)
            can_Timestamp = canmessagelist[can_number][102:114]
            wash_data[f"{mpu_Timestamp_to_can=}"] = f"{can_Timestamp=}"

            sheet.cell(row, 2).value = mpusystemtimelist[mpu_number]
            sheet.cell(row, 3).value = cansystemtimelist[can_number]
            sheet.cell(row, 4).value = mpumessagelist[mpu_number]
            sheet.cell(row, 5).value = canmessagelist[can_number]
            sheet.cell(row, 6).value = str("mpu_GNSSinf1PVTnumSV_Decimal:") + str(
                mpu_GNSSinf1PVTnumSV_Decimal) + '\r\n' + str("can_GNSSinf1PVTnumSV_Decimal:") + str(
                can_GNSSinf1PVTnumSV_Decimal) + '\r\n' + str("mpu_GNSSinf1PVTweek_Decimal:") + str(
                mpu_GNSSinf1PVTweek_Decimal) + '\r\n' + str("can_GNSSinf1PVTweek_Decimal:") + str(
                can_GNSSinf1PVTweek_Decimal) + '\r\n' + str("mpu_GNSSinf1PVTiTOW_Decimal:") + str(
                mpu_GNSSinf1PVTiTOW_Decimal) + '\r\n' + str("can_GNSSinf1PVTiTOW_Decimal:") + str(
                can_GNSSinf1PVTiTOW_Decimal) + '\r\n' + str("mpu_RTK_Longitude_Decimal:") + str(
                mpu_RTK_Longitude_Decimal) + '\r\n' + str("can_RTK_Longitude_Decimal:") + str(
                can_RTK_Longitude_Decimal) + '\r\n' + str("mpu_RTK_Latitude_Decimal:") + str(
                mpu_RTK_Latitude_Decimal) + '\r\n' + str("can_RTK_Latitude_Decimal:") + str(
                can_RTK_Latitude_Decimal) + '\r\n' + str("mpu_RTK_Height_Decimal:") + str(
                mpu_RTK_Height_Decimal) + '\r\n' + str("can_RTK_Height_Decimal:") + str(
                can_RTK_Height_Decimal) + '\r\n' + str("mpu_East_vehicle_Decimal:") + str(
                mpu_East_vehicle_Decimal) + '\r\n' + str("can_East_vehicle_Decimal:") + str(
                can_East_vehicle_Decimal) + '\r\n' + str("mpu_North_vehicle_Decimal:") + str(
                mpu_North_vehicle_Decimal) + '\r\n' + str("can_North_vehicle_speed_Decimal:") + str(
                can_North_vehicle_speed_Decimal) + '\r\n' + str("mpu_Downward_vehicle_Decimal:") + str(
                mpu_Downward_vehicle_Decimal) + '\r\n' + str("can_Downward_vehicle_speed_Decimal:") + str(
                can_Downward_vehicle_speed_Decimal) + '\r\n' + str("mpu_Track_angle_Decimal:") + str(
                mpu_Track_angle_Decimal) + '\r\n' + str("can_Track_angle_Decimal:") + str(
                can_Track_angle_Decimal) + '\r\n' + str("mpu_Longitude_STD_Decimal:") + str(
                mpu_Longitude_STD_Decimal) + '\r\n' + str("can_Longitude_STD_Decimal:") + str(
                can_Longitude_STD_Decimal) + '\r\n' + str("mpu_Latitude_STD_Decimal:") + str(
                mpu_Latitude_STD_Decimal) + '\r\n' + str("can_Latitude_STD_Decimal:") + str(
                can_Latitude_STD_Decimal) + '\r\n' + str("mpu_Height_STD_Decimal:") + str(
                mpu_Height_STD_Decimal) + '\r\n' + str("can_Height_STD_Decimal:") + str(
                can_Height_STD_Decimal) + '\r\n' + str("mpu_Horizon_DOP_Decimal:") + str(
                mpu_Horizon_DOP_Decimal) + '\r\n' + str("can_Horizon_DOP_Decimal:") + str(
                can_Horizon_DOP_Decimal) + '\r\n' + str("mpu_Position_DOP_Decimal:") + str(
                mpu_Position_DOP_Decimal) + '\r\n' + str("can_Position_DOP_Decimal:") + str(
                can_Position_DOP_Decimal) + '\r\n' + str("mpu_Vertical_DOP_Decimal:") + str(
                mpu_Vertical_DOP_Decimal) + '\r\n' + str("can_Vertical_DOP_Decimal:") + str(
                can_Vertical_DOP_Decimal) + '\r\n' + str("mpu_Timestamp_to_can:") + str(
                mpu_Timestamp_to_can) + '\r\n' + str("can_Timestamp:") + str(can_Timestamp)
            if mpu_GNSSinf1PVTnumSV_Decimal == can_GNSSinf1PVTnumSV_Decimal and mpu_GNSSinf1PVTweek_Decimal == can_GNSSinf1PVTweek_Decimal and mpu_GNSSinf1PVTiTOW_Decimal == can_GNSSinf1PVTiTOW_Decimal and mpu_RTK_Longitude_Decimal == can_RTK_Longitude_Decimal and mpu_RTK_Latitude_Decimal == can_RTK_Latitude_Decimal and mpu_RTK_Height_Decimal == can_RTK_Height_Decimal and mpu_East_vehicle_Decimal == can_East_vehicle_Decimal and mpu_North_vehicle_Decimal == can_North_vehicle_speed_Decimal and mpu_Downward_vehicle_Decimal == can_Downward_vehicle_speed_Decimal and mpu_Track_angle_Decimal == can_Track_angle_Decimal and mpu_Longitude_STD_Decimal == can_Longitude_STD_Decimal and mpu_Latitude_STD_Decimal == can_Latitude_STD_Decimal and mpu_Height_STD_Decimal == can_Height_STD_Decimal and mpu_Horizon_DOP_Decimal == can_Horizon_DOP_Decimal and mpu_Position_DOP_Decimal == can_Position_DOP_Decimal and mpu_Vertical_DOP_Decimal == can_Vertical_DOP_Decimal and mpu_Timestamp_to_can == can_Timestamp:
                # sheet.cell(row, 2).value = mpusystemtimelist[mpu_number]
                # sheet.cell(row, 3).value = cansystemtimelist[can_number]
                # sheet.cell(row, 4).value = mpumessagelist[mpu_number]
                # sheet.cell(row, 5).value = canmessagelist[can_number]
                # sheet.cell(row, 6).value = str("mpu_GNSSinf1PVTnumSV_Decimal:") + str(
                #     mpu_GNSSinf1PVTnumSV_Decimal) + '\r\n' + str("can_GNSSinf1PVTnumSV_Decimal:") + str(
                #     can_GNSSinf1PVTnumSV_Decimal) + '\r\n' + str("mpu_GNSSinf1PVTweek_Decimal:") + str(
                #     mpu_GNSSinf1PVTweek_Decimal) + '\r\n' + str("can_GNSSinf1PVTweek_Decimal:") + str(
                #     can_GNSSinf1PVTweek_Decimal) + '\r\n' + str("mpu_GNSSinf1PVTiTOW_Decimal:") + str(
                #     mpu_GNSSinf1PVTiTOW_Decimal) + '\r\n' + str("can_GNSSinf1PVTiTOW_Decimal:") + str(
                #     can_GNSSinf1PVTiTOW_Decimal) + '\r\n' + str("mpu_RTK_Longitude_Decimal:") + str(
                #     mpu_RTK_Longitude_Decimal) + '\r\n' + str("can_RTK_Longitude_Decimal:") + str(
                #     can_RTK_Longitude_Decimal) + '\r\n' + str("mpu_RTK_Latitude_Decimal:") + str(
                #     mpu_RTK_Latitude_Decimal) + '\r\n' + str("can_RTK_Latitude_Decimal:") + str(
                #     can_RTK_Latitude_Decimal) + '\r\n' + str("mpu_RTK_Height_Decimal:") + str(
                #     mpu_RTK_Height_Decimal) + '\r\n' + str("can_RTK_Height_Decimal:") + str(
                #     can_RTK_Height_Decimal) + '\r\n' + str("mpu_East_vehicle_Decimal:") + str(
                #     mpu_East_vehicle_Decimal) + '\r\n' + str("can_East_vehicle_Decimal:") + str(
                #     can_East_vehicle_Decimal) + '\r\n' + str("mpu_North_vehicle_Decimal:") + str(
                #     mpu_North_vehicle_Decimal) + '\r\n' + str("can_North_vehicle_speed_Decimal:") + str(
                #     can_North_vehicle_speed_Decimal) + '\r\n' + str("mpu_Downward_vehicle_Decimal:") + str(
                #     mpu_Downward_vehicle_Decimal) + '\r\n' + str("can_Downward_vehicle_speed_Decimal:") + str(
                #     can_Downward_vehicle_speed_Decimal) + '\r\n' + str("mpu_Track_angle_Decimal:") + str(
                #     mpu_Track_angle_Decimal) + '\r\n' + str("can_Track_angle_Decimal:") + str(
                #     can_Track_angle_Decimal) + '\r\n' + str("mpu_Longitude_STD_Decimal:") + str(
                #     mpu_Longitude_STD_Decimal) + '\r\n' + str("can_Longitude_STD_Decimal:") + str(
                #     can_Longitude_STD_Decimal) + '\r\n' + str("mpu_Latitude_STD_Decimal:") + str(
                #     mpu_Latitude_STD_Decimal) + '\r\n' + str("can_Latitude_STD_Decimal:") + str(
                #     can_Latitude_STD_Decimal) + '\r\n' + str("mpu_Height_STD_Decimal:") + str(
                #     mpu_Height_STD_Decimal) + '\r\n' + str("can_Height_STD_Decimal:") + str(
                #     can_Height_STD_Decimal) + '\r\n' + str("mpu_Horizon_DOP_Decimal:") + str(
                #     mpu_Horizon_DOP_Decimal) + '\r\n' + str("can_Horizon_DOP_Decimal:") + str(
                #     can_Horizon_DOP_Decimal) + '\r\n' + str("mpu_Position_DOP_Decimal:") + str(
                #     mpu_Position_DOP_Decimal) + '\r\n' + str("can_Position_DOP_Decimal:") + str(
                #     can_Position_DOP_Decimal) + '\r\n' + str("mpu_Vertical_DOP_Decimal:") + str(
                #     mpu_Vertical_DOP_Decimal) + '\r\n' + str("can_Vertical_DOP_Decimal:") + str(
                #     can_Vertical_DOP_Decimal) + '\r\n' + str("mpu_Timestamp_to_can:") + str(
                #     mpu_Timestamp_to_can) + '\r\n' + str("can_Timestamp:") + str(can_Timestamp)
                sheet.cell(row, 7).value = "是"
            else:
                # sheet.cell(row, 2).value = mpusystemtimelist[mpu_number]
                # sheet.cell(row, 3).value = cansystemtimelist[can_number]
                # sheet.cell(row, 4).value = mpumessagelist[mpu_number]
                # sheet.cell(row, 5).value = canmessagelist[can_number]
                # sheet.cell(row, 6).value = str("mpu_GNSSinf1PVTnumSV_Decimal:") + str(
                #     mpu_GNSSinf1PVTnumSV_Decimal) + '\r\n' + str("can_GNSSinf1PVTnumSV_Decimal:") + str(
                #     can_GNSSinf1PVTnumSV_Decimal) + '\r\n' + str("mpu_GNSSinf1PVTweek_Decimal:") + str(
                #     mpu_GNSSinf1PVTweek_Decimal) + '\r\n' + str("can_GNSSinf1PVTweek_Decimal:") + str(
                #     can_GNSSinf1PVTweek_Decimal) + '\r\n' + str("mpu_GNSSinf1PVTiTOW_Decimal:") + str(
                #     mpu_GNSSinf1PVTiTOW_Decimal) + '\r\n' + str("can_GNSSinf1PVTiTOW_Decimal:") + str(
                #     can_GNSSinf1PVTiTOW_Decimal) + '\r\n' + str("mpu_RTK_Longitude_Decimal:") + str(
                #     mpu_RTK_Longitude_Decimal) + '\r\n' + str("can_RTK_Longitude_Decimal:") + str(
                #     can_RTK_Longitude_Decimal) + '\r\n' + str("mpu_RTK_Latitude_Decimal:") + str(
                #     mpu_RTK_Latitude_Decimal) + '\r\n' + str("can_RTK_Latitude_Decimal:") + str(
                #     can_RTK_Latitude_Decimal) + '\r\n' + str("mpu_RTK_Height_Decimal:") + str(
                #     mpu_RTK_Height_Decimal) + '\r\n' + str("can_RTK_Height_Decimal:") + str(
                #     can_RTK_Height_Decimal) + '\r\n' + str("mpu_East_vehicle_Decimal:") + str(
                #     mpu_East_vehicle_Decimal) + '\r\n' + str("can_East_vehicle_Decimal:") + str(
                #     can_East_vehicle_Decimal) + '\r\n' + str("mpu_North_vehicle_Decimal:") + str(
                #     mpu_North_vehicle_Decimal) + '\r\n' + str("can_North_vehicle_speed_Decimal:") + str(
                #     can_North_vehicle_speed_Decimal) + '\r\n' + str("mpu_Downward_vehicle_Decimal:") + str(
                #     mpu_Downward_vehicle_Decimal) + '\r\n' + str("can_Downward_vehicle_speed_Decimal:") + str(
                #     can_Downward_vehicle_speed_Decimal) + '\r\n' + str("mpu_Track_angle_Decimal:") + str(
                #     mpu_Track_angle_Decimal) + '\r\n' + str("can_Track_angle_Decimal:") + str(
                #     can_Track_angle_Decimal) + '\r\n' + str("mpu_Longitude_STD_Decimal:") + str(
                #     mpu_Longitude_STD_Decimal) + '\r\n' + str("can_Longitude_STD_Decimal:") + str(
                #     can_Longitude_STD_Decimal) + '\r\n' + str("mpu_Latitude_STD_Decimal:") + str(
                #     mpu_Latitude_STD_Decimal) + '\r\n' + str("can_Latitude_STD_Decimal:") + str(
                #     can_Latitude_STD_Decimal) + '\r\n' + str("mpu_Height_STD_Decimal:") + str(
                #     mpu_Height_STD_Decimal) + '\r\n' + str("can_Height_STD_Decimal:") + str(
                #     can_Height_STD_Decimal) + '\r\n' + str("mpu_Horizon_DOP_Decimal:") + str(
                #     mpu_Horizon_DOP_Decimal) + '\r\n' + str("can_Horizon_DOP_Decimal:") + str(
                #     can_Horizon_DOP_Decimal) + '\r\n' + str("mpu_Position_DOP_Decimal:") + str(
                #     mpu_Position_DOP_Decimal) + '\r\n' + str("can_Position_DOP_Decimal:") + str(
                #     can_Position_DOP_Decimal) + '\r\n' + str("mpu_Vertical_DOP_Decimal:") + str(
                #     mpu_Vertical_DOP_Decimal) + '\r\n' + str("can_Vertical_DOP_Decimal:") + str(
                #     can_Vertical_DOP_Decimal) + '\r\n' + str("mpu_Timestamp_to_can:") + str(
                #     mpu_Timestamp_to_can) + '\r\n' + str("can_Timestamp:") + str(can_Timestamp)
                sheet.cell(row, 7).value = "否"
            diff_list = []
            loc = 8
            for k, v in wash_data.items():
                if k.split("=")[1] == v.split("=")[1]:
                    sheet.cell(row, loc).value = True
                else:
                    sheet.cell(row, loc).value = False
                    diff_list.append(k)
                    diff_list.append(v)
                    pic_dict[sheet.cell(1, loc).value] += 1
                loc += 1
            sheet.cell(row, loc).value = "\r\n".join(diff_list)
    sleep(2)
    print(pic_dict, total)
    percentage_error(pic_dict, total, sheet)
    # ----------------------将对比的数据写入excel---------------------------------
    book.save(saveExcel)
    # ----------------------将对比的数据写入excel---------------------------------


ImuDatacontinuity()
